import 'package:flutter/material.dart';

class OrderInfoCase extends StatelessWidget {
  OrderInfoCase({super.key});
  final OrderItem data = OrderItem(
      createTime: "2024-08-15 21:49:48",
      orderState: 2,
      image:
          "https://yanxuan-item.nosdn.127.net/a09de222ed32efa8ffe359b1d5780574.jpg",
      name: "保温杯是一种用于保持液体温度的容器。它能够在较长时间内维持液",
      totalNum: 2,
      curPrice: 119.5,
      totalMoney: 119.5,
      attrsText: "规格:白色240ml");

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.red,
        centerTitle: true,
        title: const Text(
          '案例-商品订单信息',
        ),
      ),
      body: Container(
        padding: const EdgeInsets.all(10),
        child: Column(
          children: [
            // 头部
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(data.createTime),
                Text(
                  data.orderState == 2 ? '待发货' : '已下单',
                  style: const TextStyle(color: Colors.orange),
                )
              ],
            ),
            // 中间
            Padding(
              padding: const EdgeInsets.only(top: 20),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  ClipRRect(
                    borderRadius: BorderRadius.circular(10),
                    child: Image.network(
                      data.image,
                      width: 100,
                      height: 100,
                      fit: BoxFit.cover,
                    ),
                  ),
                  Expanded(
                      child: Padding(
                    padding: const EdgeInsets.only(left: 10),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Expanded(child: Text(data.name)),
                            Padding(
                              padding: const EdgeInsets.only(
                                left: 10,
                              ),
                              child: Text('x${data.totalNum}'),
                            )
                          ],
                        ),
                        Padding(
                          padding: const EdgeInsets.only(top: 10),
                          child: Text(
                            data.attrsText,
                            style: const TextStyle(color: Colors.lightBlue),
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.only(top: 10),
                          child: Text(data.curPrice.toString()),
                        )
                      ],
                    ),
                  ))
                ],
              ),
            ),
            // 底部
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Column(
                  children: [
                    Text('合计：${data.totalMoney}'),
                    Padding(
                        padding: const EdgeInsets.only(top: 10),
                        child: Container(
                          padding: const EdgeInsets.symmetric(
                              horizontal: 3, vertical: 5),
                          decoration: BoxDecoration(
                            border: Border.all(
                                color: const Color.fromARGB(255, 41, 40, 40)),
                          ),
                          child: const Text('再次购买'),
                        ))
                  ],
                )
              ],
            )
          ],
        ),
      ),
    );
  }
}

class OrderItem {
  String createTime = '';
  int orderState = 0;
  String image = '';
  String name = '';
  int totalNum = 0;
  double curPrice = 0;
  double totalMoney = 0;
  String attrsText = '';
  OrderItem(
      {required this.createTime,
      required this.orderState,
      required this.image,
      required this.name,
      required this.totalNum,
      required this.curPrice,
      required this.totalMoney,
      required this.attrsText});
}
